#pragma once

namespace quiz
{

//===========================================================================
// Tree Node
//===========================================================================
struct Node
{
    unsigned int data;
    Node *       left;
    Node *       right;

    Node(
        unsigned int item
    )   : data(  item )
        , left(  NULL )
        , right( NULL )
    {}

    virtual ~Node( void ) {
        if( this->left ) {
            delete this->left;
            this->left = NULL;
        }
        if( this->right ) {
            delete this->right;
            this->right = NULL;
        }
    }
};

//===========================================================================
// Simple Binary Tree
//===========================================================================
class SimpleBinaryTree
{
public :

             SimpleBinaryTree( void );
    virtual ~SimpleBinaryTree( void );

    void   Insert( unsigned int data );
    Node * Search( unsigned int data );
    
    void ReplaceNodeValueWithSumGreater( void );

    // You are given a BST, and min, max elements. Your task is to trim this
    // BST so that it contains the elements between the min and the max
    // elements.
    void Trim(
        unsigned int min,
        unsigned int max
    );

    Node * GetRoot( void ) const { return this->m_root; }

private :

    Node * m_root;

    void Insert(
        Node **      parent,
        unsigned int data
    );

    Node * Search(
        Node *       node,
        unsigned int data
    );

    void ReplaceNodeValueWithSumGreater(
        Node * node
    );

    Node * Trim(
        Node *       node,
        unsigned int min,
        unsigned int max
    );
    
    void CleanUp( void );
    
};

};